package com.telcordia.cvas.rpn;

import java.util.concurrent.ConcurrentHashMap;

public class OperatorFactory {
	ConcurrentHashMap<String, Operator> operators = new ConcurrentHashMap<String, Operator>();
	
	public OperatorFactory() {
		operators.put("+", new Add());
		operators.put("-", new Subtract());
		operators.put("/", new Divide());
		operators.put("*", new Multiply());
		operators.put("!", new Factorial());
	}
	
	public Operator findOperatorNamed(String operatorName) {
		Operator op = null;
		
		if ("+".equals(operatorName))
			op = new Add();
		else if ("-".equals(operatorName))
			op = new Subtract();
		else if ("*".equals(operatorName))
			op = new Multiply();
		else if ("/".equals(operatorName))
			op = new Divide();
		else if ("!".equals(operatorName))
			op = new Factorial();
		else
			throw new RuntimeException(operatorName + " not registered");
		return op;
	}
}
